home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: MFC 4.0 OnDraw and DC question
- Date: 22 Jan 1996 22:32:31 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4e139v$oa9@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe6.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 22, 1996 11:50:29 in article <MFC 4.0 OnDraw and DC question>, 'Pete
- Olpe <olpe@ep.com>' wrote:
-
-
- >In my "OnDraw(CDC* pDC)" routine I call another member function that
- >performs the actual work of drawing. I pass it the pointer to the DC that
-
- >was passed to the OnDraw() routine. It is slow, and eventually bombs by
- >failing to create a font, or brush, or whatever. A very simplified
- >version of the code follows:
- >
- >myClass::OnDraw(CDC* pDC)
- >{
- >myDrawRoutine(pDC);
- >}
- >
- >myClass::myDrawRoutine(CDC* pDC)
- >{
- >create fonts, brushes, pens;
- >pDC->SelectObject(fonts, brushes, pens, etc);
- >pDC->DrawText(...);
- >}
- >
- >
- >When I substitute the code for "myDrawRoutine" back inline in the
- >"OnDraw" routine, the drawing speeds up and never seems to bomb by
- >failing to create an object or select an object into the DC.
- >
- >Does anyone have any ideas why splitting out the code from an "OnDraw"
- >routine would not work?
- >
- Often when people post code that is "similar" or "essentially the same"
- some key piece is left out. I suspect that this might be the case as
- there's no reason that an extra function call would cause such slowdown.
-
- The part of your code that could conceivably be the choking point
- in your program is the creation of fonts and brushes on every call
- to OnDraw. But that should occur the same whether you are calling
- myDrawRoutine or inserting the same code into OnDraw. I think that,
- unless some unusual circumstance prevents it, construct your
- brushes and fonts once and then keep them around for reuse
- until the program terminates. I ofter make a CFont object a member
- of my CWnd class. It's constructed and destroyed with the window.
-
- BTW, check that you're properly destroying those fonts and
- brushes. Creating them and then not releasing the resources
- can cause a crash as well as a slowdown.
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-